//package com.ytjj.qmyx.mall.api.h5.v1.order;
//
//import com.ytjj.common.api.CommonResult;
//import com.ytjj.common.api.ResultCode;
//import com.ytjj.common.controller.BaseController;
//import com.ytjj.common.model.UsersResponse;
//import com.ytjj.common.service.RedisService;
//import com.ytjj.common.utils.TokenUtil;
//import com.ytjj.qmyx.mall.model.request.*;
//import com.ytjj.qmyx.mall.model.response.OrderResponse;
//import com.ytjj.qmyx.mall.service.AlipayService;
//import com.ytjj.qmyx.mall.service.OrdersService;
//import com.ytjj.qmyx.users.client.UsersClient;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.web.bind.annotation.*;
//
//import javax.annotation.Resource;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.BufferedReader;
//import java.io.IOException;
//import java.io.InputStream;
//import java.io.InputStreamReader;
//
///**
// * 订单控制器
// *（/v1/的接口暂时没用了）
// *
// * @version 1.0
// *
// */
//@RestController
//@RequestMapping("/v1/h5Order")
//@Slf4j
//public class H5OrderOldController extends BaseController {
//
//    @Resource
//    private AlipayService alipayService;
//
//    private final OrdersService orderService;
//
//    private final UsersClient usersClient;
//
//    private final RedisService redisService;
//    //手机充值开关  1-关闭 0-开启
//    @Value("${phone.recharge.switch:1}")
//    private Integer phoneRechargeSwitch;
//
//    public H5OrderOldController(OrdersService orderService, UsersClient usersClient, RedisService redisService) {
//        this.orderService = orderService;
//        this.usersClient = usersClient;
//        this.redisService = redisService;
//    }
//
//    /**
//     * h5 创建订单
//     *
//     * @param request
//     * @return
//     */
//    @PostMapping("/h5CreateOrder")
//    public CommonResult h5CreateOrder(@RequestBody H5CreateOrderRequest request){
//        request.setOrderSource(getSource());
//        request.setChannel(TokenUtil.getChannel());
//        Integer orderId = orderService.h5CreateOrder(request);
//        return CommonResult.success(orderId);
//    }
//
//    /**
//     * 获取订单信息
//     *
//     * @return
//     */
////    @GetMapping("/getH5OrderInfoById")
////    public CommonResult getH5OrderInfoById(@RequestParam(value = "orderId") Integer orderId) {
////        UsersResponse h5CurrentUser = getH5CurrentUser();
////        return CommonResult.success(orderService.getH5OrderInfoById(orderId, h5CurrentUser));
////    }
//
//    /**
//     * 填写地址
//     *
//     * @param request
//     * @return
//     */
//    @PostMapping("/writeOrderAddress")
//    public CommonResult writeOrderAddress(@RequestBody WriteOrderAddressRequest request){
//        orderService.writeOrderAddress(request);
//        return CommonResult.success(ResultCode.SUCCESS);
//    }
//
//    /**
//     * 获取订单信息
//     *
//     * @return
//     */
//    @GetMapping("/getPaySuccessInfo")
//    public CommonResult getPaySuccessInfo(@RequestParam("orderId") Integer orderId,@RequestParam(value = "payOrderId",required = false) Integer payOrderId) {
//        UsersResponse usersResponse = getH5CurrentUser();
//        if("h5".equals(getSource())){
//            OrderResponse paySuccessInfo = orderService.getPaySuccessInfo(orderId, usersResponse, payOrderId);
//            paySuccessInfo.setScore(getH5CurrentUser().getScore());
//            return CommonResult.success(paySuccessInfo);
//        }
//        OrderResponse paySuccessInfo = orderService.getPaySuccessInfo(orderId, usersResponse,null);
//        paySuccessInfo.setScore(getH5CurrentUser().getScore());
//        return CommonResult.success(paySuccessInfo);
//    }
//
//    /**
//     * h5微信支付生产预付款订单（话费充值）
//     * @return
//     */
//    @PostMapping("/h5WxDoUnifiedPhoneOrder")
//    public CommonResult h5WxDoUnifiedPhoneOrder(@RequestBody UnifiedOrderPhoneRequest request){
//        if (phoneRechargeSwitch.equals(1)) {
//            return CommonResult.failed("充值维护中，请逛逛其它商品吧！");
//        }
//        UsersResponse usersResponse = getH5CurrentUser();
//        return CommonResult.success(orderService.h5WxDoUnifiedPhoneOrder(request,usersResponse));
//    }
//
//    /**
//     * 微信H5支付异步回调(话费充值)
//     *
//     * @param request
//     * @return
//     */
//    @PostMapping("/wxH5PhonePayNotify")
//    public String wxH5PhonePayNotify(HttpServletRequest request) {
//        try {
//            String result = orderService.wxH5PhonePayBack(this.getWxRes(request));
//            return result;
//        } catch (Exception e) {
//            log.info("微信H5支付失败:" + e.getMessage());
//            String result = "<xml>" + "<return_code><![CDATA[FAIL]]></return_code>" + "<return_msg><![CDATA[报文为空]]></return_msg>" + "</xml> ";
//            return result;
//        }
//    }
//
//    /**
//     * h5微信完成支付（话费充值）
//     * @return
//     */
//    @GetMapping("/phoneBillComplete")
//    public CommonResult phoneBillComplete(@RequestParam("orderId") Integer orderId){
//        return CommonResult.success(orderService.phoneBillComplete(orderId));
//    }
//
//    /**
//     * 获取H5订单列表
//     *
//     * @param ordersRequest
//     * @return
//     */
//    @PostMapping("/getH5OrdersList")
//    public CommonResult getH5OrdersList(@RequestBody QueryOrdersRequest ordersRequest) {
//        log.info(getH5CurrentUser().getToken());
//        log.info(TokenUtil.getToken());
//        ordersRequest.setH5Token(getH5CurrentUser().getToken());
//        return CommonResult.success(orderService.getH5OrdersList(ordersRequest));
//    }
//
//    /**
//     * h5支付生产预付款订单（微信）
//     * @param request
//     * @return
//     */
//    @PostMapping("/h5WxDoUnifiedOrder")
//    public CommonResult h5WxDoUnifiedOrder(@RequestBody UnifiedOrderRequest request){
//        UsersResponse usersResponse = getH5CurrentUser();
//        return CommonResult.success(orderService.h5WxDoUnifiedOrder(request,usersResponse));
//    }
//
//    /**
//     * H5支付异步 回调 (微信)
//     *
//     * @param request
//     * @return
//     */
//    @PostMapping("/wxH5PayNotify")
//    public String wxH5PayNotify(HttpServletRequest request) {
//        try {
//            String result = orderService.wxH5PayBack(this.getWxRes(request));
//            return result;
//        } catch (Exception e) {
//            log.info("微信H5支付失败:" + e.getMessage());
//            String result = "<xml>" + "<return_code><![CDATA[FAIL]]></return_code>" + "<return_msg><![CDATA[报文为空]]></return_msg>" + "</xml> ";
//            return result;
//        }
//    }
//
//
//    /**
//     * 手机H5支付 (支付宝)
//     *
//     * @param payRequest
//     * @return
//     */
//    @PostMapping("/h5Pay")
//    public CommonResult mobilePay(@RequestBody AlipayOrderRequest payRequest, HttpServletResponse response) {
//        return CommonResult.success(alipayService.h5PayOrder(payRequest, response,getH5CurrentUser()));
//    }
//
//
//    /**
//     * H5支付 回调 （支付宝）
//     * @param request
//     * @param response
//     * @return
//     * @throws Exception
//     */
//    @RequestMapping("/receiveH5Message")
//    public String receiveH5Message(HttpServletRequest request, HttpServletResponse response) throws Exception {
//        return alipayService.h5CallBack(request, response);
//    }
//
//    /**
//     * 获取微信响应
//     * @param request
//     * @return
//     * @throws IOException
//     */
//    private String getWxRes(HttpServletRequest request) throws IOException {
//        String resXml = "";
//        InputStream inputStream = request.getInputStream();
//        //将InputStream转换成xmlString
//        BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
//        StringBuilder sb = new StringBuilder();
//        String line = null;
//        try {
//            while ((line = reader.readLine()) != null) {
//                sb.append(line + "\n");
//            }
//        } catch (IOException e) {
//            log.info("===getWxRes==={}", e);
//        } finally {
//            try {
//                inputStream.close();
//            } catch (IOException e) {
//                e.printStackTrace();
//            }
//        }
//        resXml = sb.toString();
//        log.info(resXml);
//        return resXml;
//    }
//
//}
